package huaweiod.first;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * 华为OD机试真题 Java 实现【查找单入口空闲区域】【2022.11 Q4 新题】
 * 4 5
 * X X X X X
 * O O O O X
 * X O O O X
 * X O X X O
 * 3 4 1
 */
public class A_2023_39_FindSingleLeisureArea {

    public static void main(String[] args) {
        // 处理输入
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int n = in.nextInt();

        Character[][] matrix = new Character[m][n];
        in.nextLine();

        for (int i = 0; i < m; i++) {
            String[] strs = in.nextLine().split(" ");
            for (int j = 0; j < n; j++) {
                matrix[i][j] = strs[j].charAt(0);
            }
        }
        // process
        Map<String, Integer> resMap = new HashMap<>();
        int maxArea = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if ((i == 0 || j == 0 || i == m - 1 || j == n - 1) && matrix[i][j] == 'O') {
                    int area = getArea(copy(matrix), i, j, true);
                    if (area > 0) {
                        resMap.put(i + " " + j, area);
                        maxArea = area;
                    }
                }
            }
        }
        // 遍历结果
        int count = 0;
        String ans = "";
        for (Map.Entry<String, Integer> entry : resMap.entrySet()) {
            if (entry.getValue() == maxArea) {
                count++;
                ans = entry.getKey() + " " + entry.getValue();
            }
            if (count > 1) {
                ans = String.valueOf(maxArea);
                break;
            }
        }
        if (maxArea == 0) {
            System.out.println("NULL");
        } else {
            System.out.println(ans);
        }
    }

    public static int getArea(Character[][] matrix, int i, int j, boolean flag) {
        if (!flag) {
            if ((i == 0 || j == 0 || i == matrix.length - 1 || j == matrix[0].length - 1) && matrix[i][j] == 'O') {
                return 0;
            }
        }
        int count = 1;
        matrix[i][j] = 'X';
        int[][] distinct = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
        for (int k = 0; k < distinct.length; k++) {
            int newX = i + distinct[k][0];
            int newY = j + distinct[k][1];
            if (newX >= 0 && newY >= 0 && newX <= matrix.length - 1 && newY <= matrix[0].length - 1
                    && matrix[newX][newY] == 'O') {
                int area = getArea(matrix, newX, newY, false);
                if (area == 0) {
                    return 0;
                }
                count += area;
            }
        }
        return count;
    }

    public static Character[][] copy(Character[][] matrix) {
        Character[][] copy = new Character[matrix.length][matrix[0].length];
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                copy[i][j] = matrix[i][j];
            }
        }
        return copy;
    }

}
